package com.bodu.util;

import com.bodu.entity.InfomationColumnEntity;
import com.bodu.entity.TemplateContentEntity;
import com.bodu.entity.TemplateEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:Administrator
 * @create:2022-04-21 11:02
 */
public class TemplateContentUtils {

    /**
     * 生成模板文件内容中的相应信息
     * @return
     */
    public static TemplateContentEntity createTemplateContent(TemplateEntity template, List<InfomationColumnEntity> infomationColumnEntities, String table) {
        TemplateContentEntity content = new TemplateContentEntity();

        content.setControllerPackage(template.getControllerPackage());
        content.setControllerFilePath(template.getControllerFilePath());

        content.setServicePackage(template.getServicePackage());
        content.setServiceFilePath(template.getServiceFilePath());

        content.setServiceImplPackage(template.getServiceImplPackage());
        content.setServiceImplFilePath(template.getServiceImplFilePath());

        content.setDaoPackage(template.getDaoPackage());
        content.setDaoFilePath(template.getDaoFilePath());

        content.setDaoXmlPackage(template.getDaoXmlPackage());
        content.setDaoXmlFilePath(template.getDaoFilePath());

        content.setServResultPackage(template.getServResultPackage());
        content.setProject(template.getProject());

        String classPrefix = ObjectTransitionUtils.captionLine(table);
        content.setClassPrefix(classPrefix);

        String objectPrefix = ObjectTransitionUtils.captionWordLowerLine(table);
        content.setObjectPrefix(objectPrefix);

        content.setTable(table);

        List<Map<String, Object>> fields = new ArrayList<>();
        for (InfomationColumnEntity infomationColumnEntity: infomationColumnEntities) {
            Map<String, Object> field = new HashMap<>();
            field.put("vField", ObjectTransitionUtils.captionWordLowerLine(infomationColumnEntity.getColumnName()));
        }

        content.setFields(fields);

        return content;
    }
}
